package com.chen.nongansampling.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.chen.nongansampling.MainActivity;
import com.chen.nongansampling.R;
import com.chen.nongansampling.bean.RiskMonitoringResponseBean;
import com.chen.nongansampling.utils.StringUtils;

import java.util.List;

public class RiskMonitorRecycleViewAdapter extends  RecyclerView.Adapter<RecyclerView.ViewHolder>{
        private List<RiskMonitoringResponseBean> list;
private Context view;



//风险监测的数据更新类

//        public NewsAdapter(List<News> list) {
//            this.list = list;
//        }
       public RiskMonitorRecycleViewAdapter(Context context, List<RiskMonitoringResponseBean> list) {
            this.view = context;
            this.list=list;
       }
        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

            View v = LayoutInflater.from(view).inflate(R.layout.risk_monitor_recycleview_item, parent, false);
            RecyclerView.ViewHolder holder = null;

            holder = new MyViewHolder(v);

            return holder;
        }



        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
            ((MyViewHolder) holder).sampleName.setText(list.get(position).getSampleName());
            ((MyViewHolder) holder).sampleNumber.setText(StringUtils.changeString(list.get(position).getSampleNumber()));
            ((MyViewHolder) holder).samplingTime.setText(StringUtils.yangpin(list.get(position).getSamplingTime().split("T")[0]));
            ((MyViewHolder) holder).boothNumber.setText(StringUtils.yangpin(list.get(position).getBoothNumber()));
            ((MyViewHolder) holder).operatingHouseholds.setText(list.get(position).getOperatingHouseholds());
            ((MyViewHolder) holder).result.setText(StringUtils.jieguo(list.get(position).getResult()));
            ((MyViewHolder) holder).type.setText(StringUtils.yangpin(list.get(position).getType()));


            ((MyViewHolder) holder).sampleName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //点击条目弹出提示框
                  // Toast.makeText(v.getContext(),
                  //     "你点击的字母是："+ ((MyViewHolder) holder).sampleName.getText(),Toast.LENGTH_LONG).show();
                //点击条目进行跳转到另外一个Activity
                Intent intent=new Intent(v.getContext(), MainActivity.class);
                    v.getContext().startActivity(intent);
            }
            });




//            ((MyViewHolder) holder).time.setText(list.get(position).time);
//            ((MyViewHolder) holder).source.setText(list.get(position).source);
          //((MyViewHolder) holder).sampleName.setOnClickListener(new View.OnClickListener() {
               // @Override
                //public void onClick(View view) {
                //    myViewHolerClicks.deleteClick(position);
               // }
           // });
        }

        @Override
        public int getItemCount() {
            return list.size();
        }

    }

class MyViewHolder extends RecyclerView.ViewHolder {
    public TextView sampleName, samplingTime, boothNumber,sampleNumber,operatingHouseholds,result,type;

    public MyViewHolder(View itemView) {
        super(itemView);
        sampleName = itemView.findViewById(R.id.sampleName);
        boothNumber=itemView.findViewById(R.id.boothNumber);
        operatingHouseholds=itemView.findViewById(R.id.operatingHouseholds);
        samplingTime=itemView.findViewById(R.id.samplingTime);
        sampleNumber=itemView.findViewById(R.id.sampleNumber);
        result=itemView.findViewById(R.id.result);
        type=itemView.findViewById(R.id.type);

    }
}


